<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

</head>

<body>
    <script>
        console.log(window);
        var baseURL = 'http://localhost:3000';
        // 'http://localhost:3000/api/getaxios1'
        // 1.返回的结果是promise对象
        axios.get(baseURL + '/api/getaxios1').then(res => {
            console.log(res);
            console.log(res.data);
        });
        // 2.捕获异常的请求
        axios.get(baseURL + '/api/getaxios1111').then(res => {
            console.log(res);
            console.log(res.data);
        }).catch(err => {
            console.log(err);
        });
        // 3.接受json自动进行转换
        axios.get(baseURL + '/api/getaxios2').then(res => {
            console.log(res);
            console.log(res.data);
        }).catch(err => {
            console.log(err);
        });
        // 3.传递参数?
        axios.get(baseURL + '/api/getaxios3?username=maoweilong').then(res => {
            console.log(res);
            console.log(res.data);
        }).catch(err => {
            console.log(err);
        });
        // 4.restful形式传递参数
        axios.get(baseURL + '/api/getaxios4/u0001').then(res => {
            console.log(res);
            console.log(res.data);
        }).catch(err => {
            console.log(err);
        });
        // 5.传递参数可以使用params属性进行传递
        axios.get(baseURL + '/api/getaxios3', {
            params: {
                id: 'u0002',
                username: 'daizihang'
            }
        }).then(res => {
            console.log(res);
            console.log(res.data);
        }).catch(err => {
            console.log(err);
        });
    </script>
</body>

</html>